var say = say||{};
say.account = say.account||{};
say.account.login = say.account.login||{};

/**
 * 登录方法
 */
say.account.login.login = function(){
	var url = "/security/account/login";
	var formData = base.serializeObject($("#accountForm"));
	$.ajax({
       	type: 'post',
       	url: url,	//webservice
       	data: formData,
       	dataType:'json',	
       	success: function (result) {	
	   		if(result && result.status){
				if(result.status==1){
					layer.msg(result.msg || "登录成功",{icon:1});
					say.account.login.loginSucc(result.text);
				}else if(result.status==0){
					layer.msg(result.msg || "登录失败",{icon:1});
				}
			}
       	},
       	error: function(result){
       		alert("未知错误");
       	}
   	});
};

/**
 * 登录成功后的操作
 */
say.account.login.loginSucc = function(content){
	$(".show").removeClass("show");
	$(".hide").removeClass("hide");
	$("#logoutLi").removeClass("show");
	
	$("#loginLi").addClass("hide");
	$("#registerLi").addClass("hide");
	$("#logoutLi").addClass("show");

	var userHtml = $("#personal").html();
	userHtml = userHtml.substring(userHtml.indexOf("-")+1,userHtml.lenght);
	$("#personal").html(content+" - "+userHtml);
	
	$("#indexDiv").load("/security/account/index");
}

$(function(){
	base.setTitle("用户登录");
	//绑定事件
	$("#login").on("click",say.account.login.login);	//登录事件
});